//
//  IngredientType.m
//  demo_3
//
//  Created by 才 陈 on 12-4-2.
//  Copyright (c) 2012年 sjtu. All rights reserved.
//

#import "IngredientType.h"

@implementation IngredientType
static NSDictionary *ingredientMap = Nil;

@synthesize ingredientTypeId;
@synthesize ingredientTypeName;
@synthesize ingredentFile;

-(id) init:(NSString *)tid :(NSString *)tname :(NSString *)fpath
{
    if(self=[super init])
    {
        ingredientTypeId = tid;
        ingredientTypeName = tname;
        ingredientFile = fpath;
    }
    
    return self;
}

+(NSDictionary *) ingredientTypes:(NSDictionary *)props
{
    if(ingredientMap==Nil) 
    {    
        ingredientMap = [[NSMutableDictionary alloc] init];
        
        NSString *totalStr = [props valueForKey:@"ingredient.type.total"];
        int total = [totalStr intValue];
        
        for(int i=1; i<=total; i++)
        {
            NSString *typeIdKey = [NSString stringWithFormat:@"ingredient.type.%d.id", i];
            NSString *typeNameKey = [NSString stringWithFormat:@"ingredient.type.%d.name", i];
            NSString *typeFileKey = [NSString stringWithFormat:@"ingredient.type.%d.file", i];
            
            NSString *typeId = [props valueForKey:typeIdKey];
            NSString *typeName = [props valueForKey:typeNameKey];
            NSString *typeFile = [props valueForKey:typeFileKey];
            
            IngredientType *ingredientType = [[IngredientType alloc] init:typeId :typeName :typeFile];
            [ingredientMap setValue:ingredientType forKey:typeId];
        }
    }
    return ingredientMap;
}

@end
